﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DAL.Entities;

namespace DAL.EntitesDAL
{
    public class TKBDAL : BaseDAL, UTL.IBaseDAL
    {
        #region Implement

        public int Count()
        {
            throw new NotImplementedException();
        }

        public DataTable Select()
        {
            return ExecuteQuery("sp_SelectAll_TKB");
        }

        public DataTable Select(DateTime _ngayhoc, string _cahoc, string _lophoc)
        {
            string sql = @" Set DateFormat dmy; Select * From tb_TKB Where Ngayhoc = '{0}' And MacaID = '{1}' And MalopID = '{2}' ";
            sql = string.Format(sql, _ngayhoc, _cahoc, _lophoc);
            return ExecuteQuery(sql);
        }


        public DataTable Select_phong(DateTime _ngayhoc, string _cahoc, string _phong)
        {
            string sql = @" Set DateFormat dmy; Select * From tb_TKB Where Ngayhoc = '{0}' And MacaID = '{1}' And MaphongID = '{2}' ";
            sql = string.Format(sql, _ngayhoc, _cahoc, _phong);
            return ExecuteQuery(sql); 
        }

        public DataTable Select(object obj)
        {
            throw new NotImplementedException();
        }

        public object GetByKey(object key)
        {
            throw new NotImplementedException();
        }

        public bool Delete(string id)
        {
            throw new NotImplementedException();
        }

        public bool Delete(string id1, string id2, string id3, string id4)
        {
            var sql = "set dateformat dmy; execute sp_Delete_TKB '{0}', '{1}', '{2}', '{3}' ";
            sql = string.Format(sql, id1, id2, id3, id4);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Insert(object obj)
        {
            var o = (TKB)obj;
            var sql = "set dateformat dmy; execute sp_Insert_TKB '{0}', '{1}', '{2}', '{3}' ";
            sql = string.Format(sql, o.Ngayhoc, o.MacaID, o.MaphongID, o.MalopID);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update(object obj)
        {
            throw new NotImplementedException();
        }

        public bool Update(DateTime a, string b, string c, string d, DateTime a1, string b1, string c1, string d1)
        {
            var sql = "set dateformat dmy; execute sp_Update_TKB '{0}', '{1}', '{2}', '{3}','{4}', '{5}', '{6}', '{7}' ";
            sql = string.Format(sql, a, b, c, d, a1, b1, c1, d1);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public DataTable Search(string name)
        {
            throw new NotImplementedException();
        }


        #endregion
    }
}
